-
Notifications
You must be signed in to change notification settings - Fork 74
raidboss: sort r9s bat positions for consistency #985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
raidboss: sort r9s bat positions for consistency #985
Conversation
When tracking the bat positions it is possible for the different lines to arrive in an arbitrary order. This results in the callout being inconsistent even when the bats are in the same position. For example it might call out "away from bats S/N" instead of always consistently saying "away from bats N/S". Use sort() to make sure the bat callouts are consistent and always display the directions in the same order.
|
It bothered me that the callouts for blast beat would sometimes have the order different. It helps with readability if the order is consistent, and I think the sort for the DirectionOutput16 type will prioritize ordering them based in the north to south output. This will make it easier to parse the output and ensure that the bat position for your relative spot is easier to find quickly. (Rather than having to search for it in a set of 2 or 3 outcomes that might be in arbitrary order). |
|
I believe this will give unexpected output with the default sort function. For example, if the results were N, NNE, and ENE, the default sort function will return ENE, N, NNE, since the default sort is lexicographical order. I expect what you want is for the positions to return in N -> clockwise order, which would require a custom sort function. |
|
Something like this should give a consistent sort order, but might need to swap l/r: const [dir1, dir2] = data.bats.inner.sort((l, r) => Directions.output16Dir.indexOf(l) - Directions.output16Dir.indexOf(r)); |
An alternative would be to sort the numerical results from hdgTo16DirNum before converting them to output16Dir strings, but that would require more extensive changes. |
|
I'll likely implement common sort function in the util.ts for each of the directions based on their index and use that. Should have it updated tonight |
Add a custom sorting function for direction outputs which sorts directions based on the index in the output16Dir. This works because DirectionOutput16 is a superset of all the directions and is listed in clockwise order starting with 'dirN'. By implementing a single function we don't need to implement a separate custom function per each direction type, and we don't need to re-implement the sorting logic at each code point where sorting is required.
|
I added a compareDirectionOutput function which can take any DirectionOutput* variable and compares it using the index into the output16Dir, which I think is sufficient and avoids needing to duplicate this logic all over. |
Co-authored-by: valarnin <valarnin@gmail.com>
The indexOf returns -1 rather than undefined if the value is not in the array. This causes 'unknown' to sort to the front instead of to the back of the array. Fix this by using a lambda expression for getting the index, which checks for the case where index is less than 0, and returns the array length instead (which is after all indexes in the array). Also simplify the function by returning the difference between the indices instead of using multiple compares. This works because the compare function just needs to return negative if a is first, positive if a is second, and 0 if they have the same sort value. This is simpler than multiple separate comparisons since we know our indexes are numbers.
When tracking the bat positions it is possible for the different lines
to arrive in an arbitrary order. This results in the callout being
inconsistent even when the bats are in the same position. For example it
might call out "away from bats S/N" instead of always consistently
saying "away from bats N/S".
Use sort() to make sure the bat callouts are consistent and always
display the directions in the same order.